package com.team06.login.service;

import com.team06.login.entity.User;
import com.team06.login.service.impl.UserServiceImpl;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

@Service("userSecurityService")
public class UserSecurityService {

    public boolean isCurrentUser(Long userId) {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        if (authentication == null || !authentication.isAuthenticated()) {
            return false;
        }

        String currentUsername = authentication.getName();
        User user = (User) userService.loadUserByUsername(currentUsername);
        return user != null && user.getId().equals(userId);
    }

    private final UserServiceImpl userService;

    public UserSecurityService(UserServiceImpl userService) {
        this.userService = userService;
    }
}